package com.lin.linchatgpt.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.lin.linchatgpt.entity.Subject;
import com.lin.linchatgpt.service.SubjectService;
import com.lin.linchatgpt.utils.LinResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


/**
 * Copyright(C),2022年-2022,霖霖
 *
 * @author 霖霖
 * @version 1.0
 * @date 2023/6/15 6:30
 * @Description
 */
@RestController
@RequestMapping("lin_chat/subject")
@SaCheckLogin
public class SubjectController {
    @Resource
    private SubjectService subjectService;

    /**
     * @return com.lin.linchatgpt.utils.LinResult
     * @description 查询聊天主题列表
     * @author 霖霖
     * @date 2023/6/14 21:48
     * @params []
     */
    @GetMapping("subjects")
    public LinResult getSubjects() {

        Object loginId = StpUtil.getLoginId();

        return LinResult.success().data("list", subjectService.getSubjects(loginId.toString()));
    }

    @GetMapping("/{subjectId}")
    public LinResult getSubject(@PathVariable("subjectId") String subjectId) {
        return LinResult.success().data("item", subjectService.getById(subjectId));
    }

    @PutMapping("subject")
    public LinResult updateSubject(@RequestBody Subject subject) {
        return subjectService.updateById(subject) ? LinResult.success() : LinResult.error();
    }

    @DeleteMapping("/{subjectId}")
    public LinResult deleteSubject(@PathVariable("subjectId") String subjectId) {
        return subjectService.removeAndMessageById(subjectId) ? LinResult.success() : LinResult.error();
    }

}
